import Vue from 'vue'
import Router from 'vue-router'
import NewsList from '@/components/NewsList'
import NewDetail from '@/components/NewDetail'
import NewDetail2 from '@/components/NewDetail2'
import Shop from '@/components/Shop'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'NewsList',
      component: NewsList,

    },
    {
      path: '/shop/:id',
      name: 'shop',
      component: Shop,
      //前置守卫
      beforeEnter: (to, from, next) => {


        let isLogin = localStorage.getItem("isLogin");

        alert(isLogin)
        next()


      }
    },
    {
      path: "/news",
      component: NewsList,
      children: [
        {
          path: 'detail',
          // name: 'detail1',
          component: NewDetail2
        },
        {
          path: 'detail/:id',
          // name: 'detail',
          component: NewDetail
        },
      ]

    }



  ]
})

//前置守卫
router.beforeEach((to, from, next) => {

  // //
  let isLogin = localStorage.getItem("isLogin");
  // console.log(isLogin)
  // if(isLogin||to.path=="/"){
  // alert(isLogin)
  next()
  // }else{
  // next("/")
  // }

});
//后置
router.afterEach((to, from) => {

  let isLogin = localStorage.getItem("isLogin");
  // alert(isLogin)

});


export default router
